package com.lj.queue.param;

import com.lj.common.utils.EnumUtils;
import com.lj.queue.entity.DelayQueueMeta;
import com.lj.queue.enums.TimeUnits;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

/**
 * <p>
 * 延迟队列数据表 保存参数
 * </p>
 *
 * @author lj
 * @since 2025-07-18 17:15:03
 */
@Data
@Schema(description = "延迟队列数据表 保存参数")
public class DelayQueueMetaSaveParam {

    @Schema(description = "队列名称")
    @NotBlank(message = "队列名称 不能为空")
    private String name;

    @Schema(description = "预加载间隔")
    @Min(value = 1, message = "预加载间隔必须大于1")
    private Long preloadDistance;

    @Schema(description = "预加载时长")
    @Min(value = 1, message = "预加载时长必须大于1")
    private Long preloadDuration;

    @Schema(description = "时间单位 参考字典: TimeUnits")
    private Integer timeUnit;

    public DelayQueueMeta toEntity() {
        DelayQueueMeta entity = new DelayQueueMeta();
        entity.setName(name);
        entity.setPreloadDistance(preloadDistance);
        entity.setPreloadDuration(preloadDuration);
        entity.setTimeUnit(EnumUtils.getByValue(TimeUnits.class, timeUnit));
        return entity;
    }
}
